package com.linkage.usercenter.controller;


import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.linkage.common.base.RequestInfo;
import com.linkage.common.base.ResponseInfo;
import com.linkage.usercenter.pojo.entity.Banner;
import com.linkage.usercenter.pojo.vo.BannerVo;
import com.linkage.usercenter.service.IBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * banner表 前端控制器
 * </p>
 *
 * @author shibiao
 * @since 2020-06-08
 */
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private IBannerService bannerService;

    /**
     * 查询banner列表
     * @return
     */
    @RequestMapping("/getList")
    public String getBannerList(){
        return ResponseInfo.success(bannerService.getList()).toString();
    }

    /**
     * 新增banner
     * @param requestInfo
     * @return
     */
    @RequestMapping("/insert")
    public String insertBanner(@RequestBody RequestInfo<Banner> requestInfo){
        bannerService.insertBanner(requestInfo.getBuss());
        return ResponseInfo.success().toString();
    }

    /**
     * 分页查询banner列表
     * @param requestInfo
     * @return
     */
    @RequestMapping("/queryByPage")
    public String queryByPage(@RequestBody RequestInfo<BannerVo> requestInfo){
        PageInfo pageList = bannerService.getBannerListByPage(requestInfo);
        return ResponseInfo.success(pageList).toString();
    }

    @RequestMapping("/updateBanner")
    public String updateBanner(@RequestBody RequestInfo<Banner> requestInfo){
        bannerService.updateBanner(requestInfo.getBuss());
        return ResponseInfo.success().toString();
    }

    @PostMapping("/deleteBanner")
    public String deleteBanner(@RequestBody RequestInfo<Banner> requestInfo){
        bannerService.deleteBanner(requestInfo.getBuss().getId());
        return ResponseInfo.success("删除成功").toString();
    }

}

